package com.etc.service.impl;


import com.etc.dao.*;
import com.etc.model.Admin;
import com.etc.model.Student;
import com.etc.model.Teacher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by MZP on 2018/6/12.
 */
@Service
public class UserServiceImpl {
    @Autowired
    private TeacherMapper teacherInfo;
    @Autowired
    private StudentMapper studentInfo;
    @Autowired
    private AdminMapper databaseAdminInfo;

    public List<Teacher> getTeacherInfo(){
        List<Teacher> teachers = teacherInfo.findAll();
        return teachers;
    }
    public List<Student> getStudentInfo(){
        List<Student> students=studentInfo.findAll();
        return  students;
    }
    public void registerAdmin(Admin admin){
        databaseAdminInfo.insert(admin);
    }
    //查询管理员账号密码是否正确
    public Map<String,String> checkAdminExit( Admin admin){
        List<Admin> list = databaseAdminInfo.findByUsernameAndPassword(admin.getUsername(),admin.getPassword());
               /* findByUsernameAndPassword(admin.getUsername(), admin.getPassword())*/;

        Map<String,String> map=new HashMap<String, String>();

        if(list.size() !=0){
            map.put("Answer","TRUE");
        }
        else {
            map.put("Answer","FALSE");
        }
        return map;

    }
    //注册账号重复检测
    public Map<String, String> loginRegisterExam( Admin data){
        Map<String,String> map=new HashMap<String, String>();
        if(databaseAdminInfo.findByUsername(data.getUsername()).size() ==0 &&studentInfo.findByUsername(data.getUsername()).size() ==0 && teacherInfo.findByUsername(data.getUsername()) == null){
            map.put("Answer","TRUE");
        }
        else {
            map.put("Answer","FALSE");
        }
        return map;

    }
    //修改老师信息
    public void saveTeacher(Teacher teacher){
        teacherInfo.updateByPrimaryKey(teacher);
    }
    //新建老师信息
    public void insertTeacher(Teacher teacher){
        teacherInfo.insert(teacher);
    }
    //修改学生信息
    public void saveStudent(Student student){
        studentInfo.updateByPrimaryKey(student);
    }
    //新建学生信息
    public void insertStudent(Student student){
        studentInfo.insert(student);
    }
    //删除学生信息
    public void deleteStudent(int id){
        studentInfo.deleteById(id);
    }
    //删除老师信息
    public void deleteTeacher(int id){
        teacherInfo.deleteById(id);
    }




}
